/*
Jack Morris
11/20/14
Chapter 8
Page 178
Assinment 2
*/

#include <stdio.h>
#define DIGITS 10

int main(void)
{
   int digit_count[DIGITS] = {0};
   int digit, i;
   long n;

   printf("\nEnter a number: ");
   scanf("%ld", &n);

   // count the number of times each digit seen 
   while (n > 0) {
      digit = n % 10;                  //gets the right-most digit.
      digit_count[digit]++;            //add 1 to index matching the right-most digit.
      n /= 10;                         //remove the right-most digit from the number.
   } 

   //Print the digit header
   printf("Digit:      ");
   for (i = 0; i < DIGITS; i++)
      printf("%3d", i);

   //print occurrences
   printf("\nOccurrences:");
   for (i = 0; i < DIGITS; i++)
      printf("%3d", digit_count[i]);
   printf("\n");

   return 0;
}